package com.tensquare.recruit.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tensquare.recruit.dao.EnterpriseDao;
import com.tensquare.recruit.pojo.Enterprise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import util.IdWorker;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class EnterpriseService {
    @Autowired
    private IdWorker idWorker;
    @Autowired
    private EnterpriseDao enterpriseDao;
    public void save(Enterprise enterprise) {
        enterprise.setId(idWorker.nextId()+"");
        enterpriseDao.insert(enterprise);
    }

    public List<Enterprise> findAll() {
        return enterpriseDao.selectList(null);

    }

    public Enterprise findById(String enterpriseId) {
        return enterpriseDao.selectById(enterpriseId);
    }

    public void updateByEnterpriseId(Enterprise enterprise) {
        enterpriseDao.updateById(enterprise);
    }

    public void deleteByEnterpriseId(String enterpriseId) {
        enterpriseDao.deleteById(enterpriseId);
    }

    public Page<Enterprise> findByPage(Map<String, Object> map, Integer page, Integer size) {
        EntityWrapper<Enterprise> wrapper=new EntityWrapper<>();
        Set<String> set=map.keySet();
        for (String s : set) {
            wrapper.eq(map.get(s)!=null,s,map.get(s));
        }
        Page<Enterprise> page1=new Page<>(page,size);
        List<Enterprise> enterprises = enterpriseDao.selectPage(page1, wrapper);
        page1.setRecords(enterprises);
        return page1;
    }

    public List<Enterprise> findBySearch(Map<String, Object> map) {
        return enterpriseDao.selectByMap(map);
    }


    public Object findByHot() {
        return enterpriseDao.findByHot();
    }
}
